package nccu.model;

import com.thoughtworks.xstream.annotations.XStreamAlias;
import org.apache.commons.lang.builder.ToStringBuilder;
import org.apache.commons.lang.builder.ToStringStyle;
import org.compass.annotations.Searchable;

import javax.persistence.*;
import java.io.Serializable;

/**
 * This class is used to represent an cycle;
 *
 * @author <a href="mailto:chris.oberle@gmail.com">Chris Oberle</a>
 */
@Entity
@Table( name = "cycle",
        uniqueConstraints = {
                @UniqueConstraint( name="UNIQUE_MONTH_YEAR", columnNames = { "month", "year" } ),
                @UniqueConstraint( name="UNIQUE_NAME", columnNames = { "name" } )
        }
)
public class Cycle extends BaseObject implements Serializable {
    private static final long serialVersionUID = 3617859655330969241L;

    @Id
    @GeneratedValue(strategy = GenerationType.AUTO)
    @Column(name = "cycle_id")
    private Long id;

    @Column(name = "month", length = 15)
    private Integer month;

    @Column(name = "year", length = 15)
    private Integer year;

    @Column(name = "name", length = 15)
    private String name;

    public Cycle(){}


    public Integer getMonth() {
        return month;
    }

    public void setMonth(Integer month) {
        this.month = month;
    }

    public Integer getYear() {
        return year;
    }

    public void setYear(Integer year) {
        this.year = year;
    }

    public Long getId() {
        return id;
    }

    public void setId(Long id) {
        this.id = id;
    }

    public String getName() {
        return name;
    }

    public void setName(String name) {
        this.name = name;
    }

    @Override
    public boolean equals(Object o) {
        if (this == o) return true;
        if (!(o instanceof Cycle)) return false;

        Cycle cycle = (Cycle) o;

        if (!month.equals(cycle.month)) return false;
        if (!name.equals(cycle.name)) return false;
        if (!year.equals(cycle.year)) return false;

        return true;
    }

    @Override
    public int hashCode() {
        int result = month.hashCode();
        result = 31 * result + year.hashCode();
        result = 31 * result + name.hashCode();
        return result;
    }

    /**
     * {@inheritDoc}
     */
    public String toString() {
        ToStringBuilder sb = new ToStringBuilder(this, ToStringStyle.DEFAULT_STYLE)
                .append("cycle_id", this.id)
                .append("month", this.month)
                .append("year", this.year)
                .append("name", this.name);
        return sb.toString();
    }

}
